


#include <Arduino.h>
#include <U8g2lib.h>
#include <ESP8266WiFi.h>
#include <ESP8266_Seniverse.h>
#include <TimeLib.h>
#include <WiFiUdp.h> 

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif 

U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);

//时间-
static const char ntpServerName[] = "time1.aliyun.com";//阿里云的时间服务器
 
const int timeZone = 8;     // 时区
 
WiFiUDP Udp;
unsigned int localPort = 8888;  // local port to listen for UDP packets
 
time_t getNtpTime();
char *num_week(uint8_t dayofweek,int Mode);//计算星期
void digitalClockDisplay();
void printDigits(int digits);
void sendNTPpacket(IPAddress &address);
//-时间



const char* ssid     = "*****";       // 连接WiFi名（此处使用taichi-maker为示例）
                                            // 请将您需要连接的WiFi名填入引号中
const char* password = "*****";          // 连接WiFi密码（此处使用12345678为示例）                                         // 请将您需要连接的WiFi密码填入引号中
                                            // 请将您需要连接的WiFi密码填入引号中
// 心知天气API请求所需信息
// 请对以下信息进行修改，填入您的心知天气私钥以及需要获取天气信息的城市和温度单位
// 如需进一步了解心知天气API所提供的城市列表等信息，请前往心知天气官方产品文档网址：
// https://www.seniverse.com/docs
String reqUserKey = "******";   // 私钥
String reqLocation = "***";            // 城市
String reqUnit = "c";                      // 摄氏/华氏// 请将您需要连接的WiFi密码填入引号中
 
Forecast forecast; // 建立Forecast对象用于获取心知天气信息


//阴天-9/* (64 X 54 )*/
static const unsigned char Overcast[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0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F,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,
0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0x00,0xFE,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

//多云-4/* (64 X 64 )*/
static const unsigned char Cloudy[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x3F,0x00,0x00,
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,
0x00,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,
0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F,0x00,0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,
0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,
0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

//晴天/* (64 X 64 )*/
static const unsigned char Sunny[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFC,0x07,0x00,0x00,0x00,0x00,0x00,0xC0,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0xF0,0xFF,0xFF,0x03,0x00,0x00,0x00,0x00,0xFC,0xFF,0xFF,0x07,0x00,0x00,
0x00,0x00,0xFC,0xFF,0xFF,0x07,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x1F,0x00,0x00,0x00,0x80,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0x00,0x00,
0x00,0xE0,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0x03,0x00,0x00,0xF8,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0xFF,0x07,0x00,
0x00,0xFE,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xFE,0xFF,0xFF,0xFF,0xFF,0x1F,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,
0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,
0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0xC0,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00,0x00,0x00,0xC0,0xFF,0xFF,0x01,0x00,0x00,0x00,0x00,0x00,0xFE,0x1F,0x00,0x00,0x00,
0x00,0x00,0x00,0xFE,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

//小雨-13/* (64 X 64 )*/
static const unsigned char Lrain[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x7F,0x00,0x00,
0x00,0x00,0x00,0x00,0xFF,0xFF,0x01,0x00,0x00,0x00,0x00,0x80,0xFF,0xFF,0x03,0x00,0x00,0x00,0x1E,0xC0,0xFF,0xFF,0x07,0x00,0x00,0x80,0xFF,0xE1,0xFF,0xFF,0x0F,0x00,
0x00,0xE0,0xFF,0xE3,0xFF,0xFF,0x1F,0x00,0x00,0xF0,0xFF,0xF7,0xFF,0xFF,0x1F,0x00,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0x1F,0x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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x03,0x00,0x00,0x00,
0x00,0x00,0x00,0xE0,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

//雷阵雨-11/* (64 X 64 )*/
static const unsigned char Thundershower[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0xFE,0x1F,0x00,0x00,0x00,0x00,0x00,0x80,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0xE0,0xFF,0xFF,0x01,0x00,0x00,0x00,0x00,0xF8,0xFF,0xFF,0x03,0x00,
0x00,0x00,0x00,0xF8,0xFF,0xFF,0x03,0x00,0x00,0x00,0x04,0xFC,0xFF,0xFF,0x07,0x00,0x00,0xC0,0xFF,0xFE,0xFF,0xFF,0x1F,0x00,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,0x1F,0x00,
0x00,0xF8,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0xFE,0xFF,0xFF,0xFF,0xFF,0x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FF,0xFF,0x3F,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0xFC,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F,0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,
0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0x03,0x00,0x00,0x00,0x00,0xFE,0x3F,0x00,0x00,0x00,
0x00,0x00,0x00,0xFE,0x3F,0x00,0x00,0x00,0x00,0x20,0x00,0xFE,0x1F,0x00,0x06,0x00,0x00,0xF8,0x00,0xFE,0x07,0x00,0x1F,0x00,0x00,0xFC,0x00,0xFF,0x07,0x00,0x1F,0x00,
0x00,0xFC,0x00,0xFF,0x03,0x80,0x1F,0x00,0x00,0x7E,0x00,0xFF,0x3F,0x80,0x1F,0x00,0x00,0x7E,0x80,0xFF,0x1F,0xC0,0x07,0x00,0x00,0x7E,0x80,0xFF,0x07,0xC0,0x07,0x00,
0x00,0x7E,0x80,0xFF,0x07,0xC0,0x07,0x00,0x00,0x3F,0xC0,0xFF,0x03,0xC0,0x07,0x00,0x00,0x3F,0x00,0xFC,0x01,0xE0,0x03,0x00,0x80,0x1F,0x00,0xFE,0x00,0xE0,0x03,0x00,
0x80,0x1F,0x00,0x7E,0x00,0xF8,0x01,0x00,0x80,0x1F,0x00,0x3E,0x00,0xF8,0x01,0x00,0x80,0x07,0x00,0x1F,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00
};

void setup(){
  Serial.begin(9600);          
  Serial.println("");
  u8g2.begin();
  
  connectWiFi();   // 连接wifi
 
 
  Udp.begin(localPort);
  Serial.print("Local port: ");
  Serial.println(Udp.localPort());

  Serial.println("waiting for sync");
  setSyncProvider(getNtpTime);
  setSyncInterval(300);
  // 配置心知天气请求信息
  forecast.config(reqUserKey, reqLocation, reqUnit); 
 

}
 
void loop(){
  u8g2.clearBuffer();  
  static int i=0,j=0;
  
  if(i==0)
  {  
     i=1;
     u8g2.clearBuffer();          // clear the internal memory
     u8g2.setFont(u8g2_font_ncenB10_tr); // choose a suitable font
     u8g2.drawStr(7,40,"Connecting ...");  // write something to the internal memory
     u8g2.sendBuffer();          // transfer internal memory to the display
     delay(2000);  
  }
  now();

  digitalClockDisplay();
  delay(300);

  if(++j==20)
  {
     j=0;
     if(forecast.update())
     {             // 更新天气信息
        for(int m = 0; m < 3; m++)
       {
         u8g2.firstPage();
         u8g2.setFontMode(1);
         do
         {
          u8g2.setFont(u8g2_font_ncenB10_tr);
          u8g2.setCursor(12, 15);//设置显示位置
          switch(m)
          {
            case 0:u8g2.print("  ---Today--- ");break;
            case 1:u8g2.print(" --Tomorrow--");break;
            case 2:u8g2.print("Af Tomorrow");break;
          }
          delay(45);
          
        
         u8g2.setCursor(15, 35);//设置显示位置
         u8g2.print(String(forecast.getDayText(m)));
         delay(45);
        
         u8g2.setCursor(15, 55);//设置显示位置
         u8g2.print("T: " + String(forecast.getLow(m)) + "-" + String(forecast.getHigh(m))); 
         }
         while (u8g2.nextPage());
         delay(2000);  
         u8g2.clearDisplay();
         u8g2.firstPage();
         do 
         {
           u8g2.setFont(u8g2_font_ncenB14_tr);
           switch(forecast.getDayCode(m))
           {
            case 9:u8g2.drawXBMP(32,0, 64, 54, Overcast);break;  //阴天
            case 4:u8g2.drawXBMP(32,0, 64, 64, Cloudy);break;    //多云
            case 0:u8g2.drawXBMP(32,0, 64, 64, Sunny);break;    //晴天
            case 13:u8g2.drawXBMP(32,0, 64, 64, Lrain);break;    //小雨
            case 11:u8g2.drawXBMP(32,0, 64, 64, Thundershower);break; //雷阵雨
          }
         } while ( u8g2.nextPage() );
         delay(2000);  
       }
     }
  }                                            
 
}




// 连接WiFi
void connectWiFi(){
  WiFi.begin(ssid, password);                  // 启动网络连接
  Serial.print("Connecting to ");              // 串口监视器输出网络连接信息
  Serial.print(ssid); Serial.println(" ...");  // 告知用户NodeMCU正在尝试WiFi连接
  
  int i = 0;                                   // 这一段程序语句用于检查WiFi是否连接成功
  while (WiFi.status() != WL_CONNECTED) {      // WiFi.status()函数的返回值是由NodeMCU的WiFi连接状态所决定的。 
    delay(1000);                               // 如果WiFi连接成功则返回值为WL_CONNECTED                       
    Serial.print(i++); Serial.print(' ');      // 此处通过While循环让NodeMCU每隔一秒钟检查一次WiFi.status()函数返回值
  }                                            // 同时NodeMCU将通过串口监视器输出连接时长读秒。
                                               // 这个读秒是通过变量i每隔一秒自加1来实现的。                                              
  Serial.println("");                          // WiFi连接成功后
  Serial.println("Connection established!");   // NodeMCU将通过串口监视器输出"连接成功"信息。
  Serial.print("IP address:    ");             // 同时还将输出NodeMCU的IP地址。这一功能是通过调用
  Serial.println(WiFi.localIP());              // WiFi.localIP()函数来实现的。该函数的返回值即NodeMCU的IP地址。  
}

void digitalClockDisplay()
{
  // digital clock display of the time
  
  String Dates = String(year()) + "-" + String(month()) + "-" + String(day());   
  String Times = String(hour()) + ":" + Digit(minute()) + ":" + Digit(second());
  u8g2.firstPage();
  u8g2.setFontMode(1);
  do
  {
    u8g2.setFont(u8g2_font_ncenB14_tr);
    //u8g2.setFont(u8g2_font_inb16_mf);
    u8g2.setCursor(19, 15);//设置显示位置
    u8g2.print("--CLOCK--");
    delay(45);

    
    u8g2.setCursor(18, 35);//设置显示位置
    u8g2.print(Dates);
    delay(45);
    
    u8g2.setCursor(26, 55);//设置显示位置
    u8g2.print(Times); 


  }
  while (u8g2.nextPage());

  Serial.print(num_week(weekday(),4));
  Serial.println();
}

String Digit(int digits)
{
  // utility for digital clock display: prints preceding colon and leading 0
  if (digits < 10)
    return '0' + String(digits);
  else
    return String(digits);
}
/*
@功能:判断星期并赋值
*/
char week1[10],week2[8],week3[2],week4[4];
char *num_week(uint8_t dayofweek,int Mode){
  switch(dayofweek)
  {
    case 1: 
    strcpy(week1,"Sunday");
    strcpy(week2,"周日");
    strcpy(week3,"Su");
    strcpy(week4,"日"); 
      break;
    case 2: 
    strcpy(week1,"Monday");
    strcpy(week2,"周一");
    strcpy(week3,"Mo");
    strcpy(week4,"一"); 
      break;
    case 3: 
    strcpy(week1,"Tuesday");
    strcpy(week2,"周二");
    strcpy(week3,"Tu");
    strcpy(week4,"二"); 
      break;
    case 4: 
    strcpy(week1,"Wednesday");
    strcpy(week2,"周三"); 
    strcpy(week3,"We");
    strcpy(week4,"三"); 
      break;
    case 5: 
    strcpy(week1,"Thursday");
    strcpy(week2,"周四"); 
    strcpy(week3,"Th");
    strcpy(week4,"四"); 
      break;
    case 6: 
    strcpy(week1,"Friday");
    strcpy(week2,"周五");
    strcpy(week3,"Fr"); 
    strcpy(week4,"五");
      break;
    case 7: 
    strcpy(week1,"Saturday");
    strcpy(week2,"周六"); 
    strcpy(week3,"Sa");
    strcpy(week4,"六");
      break;
    default:
    strcpy(week1,"NO");
    strcpy(week2,"无");
    strcpy(week3,"NO");
    strcpy(week4,"无");
      break; 
  }
  switch(Mode)
  {
    case 1: return week1; break;
    case 2: return week2; break;
    case 3: return week3; break;
    case 4: return week4; break;
  }
}



/*-------- NTP code (下面不用看哦)----------*/
 
const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message
byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming & outgoing packets
 
time_t getNtpTime()
{
  IPAddress ntpServerIP; // NTP server's ip address
 
  while (Udp.parsePacket() > 0) ; // discard any previously received packets
  Serial.println("Transmit NTP Request");
  // get a random server from the pool
  WiFi.hostByName(ntpServerName, ntpServerIP);
  Serial.print(ntpServerName);
  Serial.print(": ");
  Serial.println(ntpServerIP);
  sendNTPpacket(ntpServerIP);
  uint32_t beginWait = millis();
  while (millis() - beginWait < 1500) {
    int size = Udp.parsePacket();
    if (size >= NTP_PACKET_SIZE) {
      Serial.println("Receive NTP Response");
      Udp.read(packetBuffer, NTP_PACKET_SIZE);  // read packet into the buffer
      unsigned long secsSince1900;
      // convert four bytes starting at location 40 to a long integer
      secsSince1900 =  (unsigned long)packetBuffer[40] << 24;
      secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
      secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
      secsSince1900 |= (unsigned long)packetBuffer[43];
      return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR;
    }
  }
  Serial.println("No NTP Response :-(");
  return 0; // return 0 if unable to get the time
}
 
// send an NTP request to the time server at the given address
void sendNTPpacket(IPAddress &address)
{
  // set all bytes in the buffer to 0
  memset(packetBuffer, 0, NTP_PACKET_SIZE);
  // Initialize values needed to form NTP request
  // (see URL above for details on the packets)
  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
  packetBuffer[1] = 0;     // Stratum, or type of clock
  packetBuffer[2] = 6;     // Polling Interval
  packetBuffer[3] = 0xEC;  // Peer Clock Precision
  // 8 bytes of zero for Root Delay & Root Dispersion
  packetBuffer[12] = 49;
  packetBuffer[13] = 0x4E;
  packetBuffer[14] = 49;
  packetBuffer[15] = 52;
  // all NTP fields have been given values, now
  // you can send a packet requesting a timestamp:
  Udp.beginPacket(address, 123); //NTP requests are to port 123
  Udp.write(packetBuffer, NTP_PACKET_SIZE);
  Udp.endPacket();
}
